<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <select-user-by-dep v-model="queryParam.projectLeading"></select-user-by-dep>
              </a-form-item>
            </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="项目承接人" >
              <select-user-by-dep :multi="false" v-model="queryParam.undertaker" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-company-input v-model="queryParam.signUnit" :multi="false"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-model-item label="实施部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executeDepart">
                  <j-select-depart v-model="queryParam.executeDepart" placeholder="请选择实施部门"/>
                </a-form-model-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <!-- <a-form-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <business-category-select
                  v-model="queryParam.code" @back="handleCategoryNameQuery"/>
              </a-form-item> -->
              <a-form-item label="业务名称" class="form-item">
              <!-- <a-input placeholder="请输入业务名称" v-model="queryParam.categoryName"></a-input> -->
              <business-category-name-select v-model="queryParam.code" @back="handleCategoryNameQuery"/>
            </a-form-item>
            </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ywmc">
              <a-input :disabled=formDisabled v-model="queryParam.ywmc" placeholder="请输入业务名称"></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionTeam">
              <select-team-input
                  placeholder="请选择生产团队"
                  v-model="queryParam.productTeam"
                  :tdlx="2"
                  :teamType="0"
                  :triggerChange="true"/>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button type="primary" icon="download" :loading="exportLoading" @click="handleExportXls('项目一览表汇总表')" :disabled="isDisabledAuth('erpFinanceTeamManager:export')">导出</a-button> -->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle"/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <a slot="billNo" slot-scope="text, record" @click="getDetail(record)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <!-- 字符串超长截取省略号显示-->
        <template slot="ellipsis" slot-scope="text">
          <j-ellipsis :value="text"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">

        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpReportAudit:viewTrack')">审批进度</a-button>
        </template>
        </span>
      </a-table>
    </div>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
     <erp-project-report-modal ref="modalForm" @ok="modalFormOk"></erp-project-report-modal>
    <!-- <erp-project-finance-reimbursement-list ref="reimburForm" ></erp-project-finance-reimbursement-list>  -->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import moment from 'moment'
  import BpmProcessTrackModal from "@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue";

  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal.vue'
  import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
  import AddressChoice from '@/components/AddressChoice/AddressChoice';
  import ErpProjectFinanceReimbursementList from '@/views/erp/report/project/modules/ErpProjectFinanceReimbursementList.vue'
  import { getAction } from '@/api/manage';
  import address from '@/components/AddressChoice/address.js'
  import BusinessCategorySelect from "@/views/erp/components/BusinessCategorySelect.vue";

  export default {
    name: 'ErpOmcReportReviewChecklist',
    mixins: [ JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin ],
    components: {
      AddressChoice,
      ErpProjectReportModal,
      BpmProcessTrackModal,
      BusinessCategorySelect,
      SelectProjectInput,
      BusinessCategoryNameSelect,
      SelectCustomerInput,
      SelectCompanyInput,
      SelectUserByDep,
      SelectTeamInput,
      ErpProjectFinanceReimbursementList
    },
    data () {
      return {
        signUnitDate: [moment().startOf('year').format('YYYY-MM-DD'), moment(new Date()).format('YYYY-MM-DD')],
        queryParam: {
          // signUnitDate_begin: moment().startOf('year').format('YYYY-MM-DD'),
          // signUnitDate_end: moment(new Date()).format('YYYY-MM-DD')
        },
        createTimeRange: [],
        flowCode:'',
        beanName:'',
        projectEstablishDateRange: [],
        description: '项目一览表',
        // 表头
        columns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '单据编号',
            align: 'center',
            dataIndex: 'billNo',
            scopedSlots: { customRender: 'billNo' },
            ellipsis: true,
            width: 200
          },
          {
            title: '申请人',
            align: 'center',
            dataIndex: 'handlerId_dictText',
            ellipsis: true,
            width: 185
          },
          {
            title: '申请部门',
            align: 'center',
            dataIndex: 'handlerDeptId_dictText',
            ellipsis: true,
            width: 150
          },
          {
            title: '项目名称',
            align: 'center',
            dataIndex: 'projectId_dictText',
            ellipsis: true,
            width: 150
          },
          {
            title: '项目负责人',
            align: 'center',
            dataIndex: 'projectLeading_dictText',
            width: 250,
            ellipsis: true
          },
          {
            title: '生产团队',
            align: 'center',
            dataIndex: 'productTeam_dictText',
            ellipsis: true,
            width: 230
          },
          {
            title: '实施部门',
            align: 'center',
            dataIndex: 'executeDepart_dictText',
            width: 250,
            ellipsis: true
          },
          {
            title: '签订单位',
            align: 'center',
            dataIndex: 'signUnit_dictText',
            width: 250,
            ellipsis: true
          },
          {
            title: '业务名称',
            align: 'center',
            dataIndex: 'categoryName',
            width: 200,
            ellipsis: true
          },
          // {
          //   title: '项目所在地',
          //   align: 'center',
          //   dataIndex: 'projectAddress',
          //   ellipsis: true,
          //   width: 200
          // },
          {
            title: '单据状态',
            align: 'center',
            dataIndex: 'bpmStatus_dictText',
            key: 'economize',
            ellipsis: true,
            width: 200
          },
          {
            title: '操作',
            align: 'center',
            dataIndex: 'action',
            ellipsis: true,
            width: 200,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          },
        
        ],
        // 列设置
        settingColumns: [],
        url: {
          list: '/api/erp/omc/reportaudit/erpReportAudit/allList',
          // exportXlsUrl: '/api/erp/project/report/erpProjectReport/exportXls'
        },
        // 代码生成后需手动设置流程编码
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {

      handleTrack(record) {
        if(record.billNo && record.billNo.substring(0, 2) == 'ZF') {
        this.flowCode = 'dev_erp_report_audit_001'
        this.beanName = 'ErpReportAuditCancelFlow'
      } else {
        this.flowCode = 'onl_erp_report_audit'
        this.beanName = 'ErpReportAuditFlow'
      }
      var params = { flowCode: this.flowCode, dataId: record.id };// 查询条件
      this.$refs.bpmProcessTrackModal.handleTrack(params);
      this.$refs.bpmProcessTrackModal.title = '审批跟踪记录';
    },

      handleCategoryNameQuery(data){
         console.log(data,'data-------');
         
        this.queryParam.categoryName = data.categoryName
      },
      getDetail(record) {
        this.$nextTick(() => {
          this.$router.push({
          path: `/reportaudit/ErpReportAuditListDetail/${record.id}`,
        })
        })
      },
      getReimbursementDetail(record) {
        this.$refs.reimburForm.initData(record.id);
        this.$refs.reimburForm.visible = true;
      },
      getContractDetail(record) {
        this.$nextTick(() => {
          this.$refs.modalForm.getContractDetail(record);
          this.$refs.modalForm.title = '项目一览表';
        })
      },

      initDictConfig() {
      },
      searchReset() {
        this.queryParam = {}
        this.projectEstablishDateRange = []
          this.loadData(1)
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'date', value: 'createTime', text: '创建日期' })
        fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
        fieldList.push({ type: 'string', value: 'billNo', text: '单据编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
        fieldList.push({ type: 'string', value: 'applicant', text: '申请公司', dictCode: '' })
        fieldList.push({ type: 'string', value: 'isRelContract', text: '是否关联合同', dictCode: 'yes_no' })
        fieldList.push({ type: 'string', value: 'payMode', text: '支付方式(字典)', dictCode: 'payment_type' })
        fieldList.push({ type: 'string', value: 'payeeName', text: '收款方名称', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payeeBankName', text: '收款方开户行', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payeeAccountNo', text: '收款方账户', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payeeContacts', text: '收款联系人', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payeeContactInfo', text: '收款联系方式', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payRemark', text: '打款备注', dictCode: '' })
        fieldList.push({ type: 'Text', value: 'attachments', text: '附件', dictCode: '' })
        this.superFieldList = fieldList
      },
      businessCategoryHandle(obj) {
        if (obj) {
          this.queryParam.businessCategory = obj.categoryCode;
        }
      },
      handleReset() {
        this.projectEstablishDateRange = [];
        this.allSearchReset();
      },
      async loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;

          if (this.rowSpanPagination) {
            this.rowSpanPagination.current = 1;
            this.rowSpanPagination.pageNo = 1
          }
        }
        var params = this.getQueryParams();// 查询条件
        // params.status = '2'
        params.billStatus = 'not_voided,invalid_in_progress'
        params.bpmStatus = '3'
        params.billType = 'create'
        delete params.permissionType
        this.loading = true;
        let res = await getAction(this.url.list, params)
        this.loading = false;
        if (res.success) {
          this.dataSource = res.result ? res.result.records : []
          this.ipagination.total = res.result ? res.result.total : ''
          // 判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1);
          }

          if (this.rowSpanPagination) {
            this.rowSpanPagination.pageSize = this.dataSource.length
            this.rowSpanPagination.total = res.result ? res.result.total : ''
          }

          const data = [...this.dataSource];
          if (this.queryParam.bizTaskType == '1') {
            for (var i = 0; i < data.length; i++) {
              // item.taskUrge = false;
              var item = data[i];
              var params = { flowCode: this.flowCode, dataId: item.id };// 查询条件
              let res2 = await getAction(this.url.checkNotify, params);
              if (res2.result) {
                item.taskUrge = true;
              }
            }
          }
          this.dataSource = data;
        }
        this.bizCount();
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
